﻿@model PagedList<YiYiTong.Rocket.Model.Manager.UserModel>
@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("UserList", "User")" method="get">
    <p>
        用户名：
        <input type="text" name="loginName" id="loginName" class="abc input-default" placeholder="" value="@Request.QueryString["loginName"]">&nbsp;
        用户状态：
        <select id="userStatus" name="userStatus">
            <option value="-10" @(Request.QueryString["userStatus"] == "-10" ? "selected" : "")>全部状态</option>
            <option value="1" @(Request.QueryString["userStatus"] == "1" ? "selected" : "")>启用</option>
            <option value="2" @(Request.QueryString["userStatus"] == "2" ? "selected" : "")>禁用</option>
        </select>&nbsp;
        创建时间：
        <input type="text" name="begTime" class="calendar" id="begTime" value="@Request.QueryString["begTime"]"> - <input type="text" name="endTime" class="calendar" id="endTime" value="@Request.QueryString["endTime"]">&nbsp;
        <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp; <button type="button" class="btn btn-success" id="addnew">添加用户</button>
    </p>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>用户编号</th>
            <th>用户名</th>
            <th>真实姓名</th>
            <th>用户状态</th>
            <th>创建时间</th>
            <th>手机号</th>
            <th>邮箱</th>
            <th>用户角色</th>
            <th>管理操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
                <tr class="@HtmlPagerHelper.TrClass(index++)">
                <td>@m.uid</td>
                <td>@m.loginName</td>
                <td>@m.realName</td>
                <td>
                    @switch (m.userStatus)
                    {
                        case 1:
                            @:<span style="color: #0b5f21">启用</span>
                            break;
                        case 2:
                            @:<span>禁用</span>
                            break;
                    }
                </td>
                <td>@m.createTime.ToString("yyyy-MM-dd")</td>
                <td>@m.mobile</td>
                <td>@m.email</td>
                <td>@Html.Action("GetUserRoleNames", "User", new { UID = m.uid })</td>
                <td>
                    <a href="@Url.Action("Register", "User", new { UID = m.uid})">编辑</a>
                    <a href="javascript:void(0);" onclick="SetPwd(@m.uid)">重置密码</a>
                    <a href="@Url.Action("SetRole", "User", new { UID = m.uid, LoginName = m.loginName })">设置角色</a>
                    <a href="javascript:void(0);" onclick="Delete(@m.uid)">删除</a>
                </td>
            </tr>
        }
    }
</table>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    function Delete(UID) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要删除该用户吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("DelUser", "User")";
                      parameter = { UID: UID };
                      $.post(url, parameter, function (result) {
                          if (result.Message != undefined) {
                              BUI.Message.Alert(result.Message, function () {
                                  location.href = result.Body;
                              }, 'success');
                          }
                          else {
                              var substr = cutstr(result, "BUI.Message.Alert", "function");
                              substr = substr.replace("'", "").replace("'", "").replace("(", "").replace(",", "");
                              if (substr == "")
                                  BUI.Message.Alert("操作失败，请联系技术人员", 'warning');
                              else {
                                  if (substr.indexOf("请重新登录") > 0) {
                                      BUI.Message.Alert(substr, function () {
                                          top.location.href = "@Url.Action("Login","User")";
                                      }, 'warning');
                                  }
                                  else {
                                      {
                                          if (substr.indexOf("请重新登录") > 0) {
                                              BUI.Message.Alert(substr, function () {
                                                  top.location.href = "@Url.Action("Login","User")";
                                              }, 'warning');
                                          }
                                          else {
                                              BUI.Message.Alert(substr, 'warning');
                                          }
                                      }
                                  }
                              }
                          }
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }

    function SetPwd(uid) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要重置该用户密码吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("SetPwd", "User")";
                      parameter = { UID: uid };
                      $.post(url, parameter, function (result) {
                          if (result.Message != undefined) {
                              if (result.IsSuccess) {
                                  //成功
                                  BUI.Message.Alert(result.Message + ",新密码是：" + result.Body, 'success');
                              }
                              else {
                                  BUI.Message.Alert(result.Message, 'success');
                              }
                          }
                          else {
                              var substr = cutstr(result, "BUI.Message.Alert", "function");
                              substr = substr.replace("'", "").replace("'", "").replace("(", "").replace(",", "");
                              if (substr == "")
                                  BUI.Message.Alert("操作失败，请联系技术人员", 'warning');
                              else {
                                  if (substr.indexOf("请重新登录") > 0) {
                                      BUI.Message.Alert(substr, function () {
                                          top.location.href = "@Url.Action("Login","User")";
                                      }, 'warning');
                                  }
                                  else {
                                      {
                                          if (substr.indexOf("请重新登录") > 0) {
                                              BUI.Message.Alert(substr, function () {
                                                  top.location.href = "@Url.Action("Login","User")";
                                              }, 'warning');
                                          }
                                          else {
                                              BUI.Message.Alert(substr, 'warning');
                                          }
                                      }
                                  }
                              }
                          }
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }

    $(function () {
        $('#addnew').on('click', function () {
            window.document.location.href = "@Url.Action("Register","User")";
        });
    });
</script>